<%--
  Author: chengwei
  Date: 2016/5/13
  Time: 16:50
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="/resource/bootstrap/css/bootstrap.min.css">

    <!-- 可选的Bootstrap主题文件（一般不用引入） -->
    <%--<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">--%>

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="/resource/js/jquery.min.js"></script>

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="/resource/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
    <form id="frm" method="post"  enctype="multipart/form-data">
        <input type="hidden" name="" value="${d.type}">
        <label for="exampleInputFile">选择文件</label>
        <input type="file" id="exampleInputFile" name="file">
    </form>
    <button type="button" onclick="doSubmit();" class="btn btn-default">提交</button>
</body>
<script>
    function doSubmit() {
//        var $frm = $("#frm").serializeArray();
        var formData = new FormData($( "#frm" )[0]);
//        $.post("/file/upload.do", formData, function(data){
//            alert("Data Loaded: " + data);
//        });

//        $.ajax({
//            type: "post",
//            url: "/file/upload.do",
//            data: formData,
//            success: function(msg){
//                alert( "Data Saved: " + msg );
//            }
//        });
//
//        var formData = new FormData($( "#uploadForm" )[0]);
        $.ajax({
            url: '/file/upload.do' ,
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (returndata) {
                alert(returndata);
                console.info($.parseJSON(returndata));
            },
            error: function (returndata) {
                alert(returndata);
            }
        });
    }
</script>
</html>
